using AvalonAdmin.BaseViewModel;
using AvalonAdmin.Pages.Sys.ViewModels;
using Avalonia;
using Avalonia.Controls;
using Ursa.Controls;

namespace AvalonAdmin.BaseControl
{
    public class BaseUserControl : UserControl
    {
        protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
        {
            base.OnAttachedToVisualTree(e);
            var _topLevel = TopLevel.GetTopLevel(this);
            if (_topLevel is null)
                return;

            var vm = DataContext as Base;
            if (vm != null)
            {
                if (!WindowNotificationManager.TryGetNotificationManager(_topLevel, out var manager))
                {
                    manager = new WindowNotificationManager(_topLevel);
                }
                vm.NotificationManager = manager;
            }
        }
    }
}
